﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using XYAC.Framework.MonitorTireMaterialManual.Entities;
using XYAC.Framework.MonitorTireMaterialManual.IServices;
using XYAC.Framework.MonitorTireMaterialManual.ViewModels;

namespace XYAC.Framework.MonitorTireMaterialManual.Views
{
    /// <summary>
    /// QualityDataUploadView.xaml 的交互逻辑
    /// </summary>
    public partial class QualityDataUploadView : UserControl
    {
        public QualityDataUploadView(QualityDataUploadViewModel viewModel, ILogger<QualityDataUploadView> logger, IServiceProvider provider)
        {
            InitializeComponent();
            this.DataContext = this.ViewModel = viewModel;
            this.Logger = logger;
            this.Provider = provider;
            RefershDetectionMachine();
        }
        /// <summary>
        /// 刷新检测机台
        /// </summary>
        private void RefershDetectionMachine()
        {
            try
            {
                using (var scope = this.Provider.CreateScope())
                {
                    var service = scope.ServiceProvider.GetService<ILocalDataService>();
                    var DetectionMachineList = service.GetAll<Entities.EquipmentMapping>();
                    this.TabMachines.ItemsSource = DetectionMachineList;
                    this.TabMachines.SelectedIndex = 0;
                    this.ViewModel.SelectedDetectionMachine = DetectionMachineList.FirstOrDefault();
                }
            }
            catch (Exception)
            {

            }
        }
        public ILogger Logger { get; }
        public IServiceProvider Provider { get; }
        public QualityDataUploadViewModel ViewModel { get; }

        private void DatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            this.ViewModel.UpdateCustomizePlanDateWithConfig((sender as DatePicker).SelectedDate);

        }

    }
}
